﻿using Coleotrack.Service.Registration;
using NHibernate;
using NUnit.Framework;
using StructureMap;

namespace Coleotrack.Test.Infrastructure
{
    [TestFixture]
    public class NHibernate
    {
        [Test]
        public void SessionFactoryShouldBeSingleton()
        {
            const string connectionString = @"Data Source=.\sqlexpress;Initial Catalog=Coleotrack;Persist Security Info=True;User ID=coleotrack;Password=coleotrack";

            ObjectFactory.Initialize(x =>
                                         {
                                             x.AddRegistry(new NHibernateRegistry(connectionString, true));
                                             x.AddRegistry<ServiceRegistry>();
                                         });

            var factory = ObjectFactory.GetInstance<ISessionFactory>();
            var factory2 = ObjectFactory.GetInstance<ISessionFactory>();

            Assert.AreSame(factory, factory2);
        }
    }
}